package com.wechat.shopping.mall.account.controller;

import com.wechat.shopping.mall.account.domain.SaveCustomerParam;
import com.wechat.shopping.mall.account.service.CustomerInfoService;
import com.wechat.shopping.mall.util.ResponseMessage;
import com.wechat.shopping.mall.util.ValidUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@Api(value = "组织机构操作")
@RequestMapping(value = "/customers")
public class CustomerInfoController {
    private static final Logger LOG = LoggerFactory.getLogger(CustomerInfoController.class);

    @Autowired
    private CustomerInfoService customerInfoService;

    @RequestMapping(value = "/customer/info",method = RequestMethod.POST)
    @ApiOperation(value = "组织机构创建",notes = "创建组织机构",httpMethod = "POST",response = ResponseMessage.class)
    public ResponseMessage saveCustomer(@Valid @RequestBody SaveCustomerParam saveCustomerParam, BindingResult error) {
        if (error.hasErrors()) {
            return ResponseMessage.error(ValidUtils.getErrorMessage(error));
        }
        return customerInfoService.saveCustomer(saveCustomerParam);
    }
}
